/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.devel.designpatterns.composite;

import com.devel.designpatterns.visitor.Visitor;
import java.util.ArrayList;

/**
 *
 * @author wm.devel
 */
public class Composite extends Component {
    
    ArrayList<Component> children = new ArrayList<Component>();

    @Override
    public void accept(Visitor v) {
        v.visitCompositeStart(this);
        for (Component child : children) {
            child.accept(v);
        }
        v.visitCompositeEnd(this);
    }
    
    @Override
    public void add(Component component) {
        children.add(component);
    }

    @Override
    public void remove(Component component) {
        children.remove(component);
    }

    @Override
    public Component getChild(int index) {
        return children.get(index);
    }
    
    public int size() {
        return children.size();
    }

    @Override
    public String toString() {
        return "Composite{" + "children=" + children.size() + '}';
    }

 }
